import 'package:constellation/global.dart';
import 'package:constellation/widgets/avatar.dart';
import 'package:flutter/material.dart';

class ConstellationModal {
  static show({BuildContext context, constellation, onChange}) {
    modalChildren() {
      List<Widget> list = [];
      List.generate(Global.constellationList.length, (index) {
        var _data = Global.constellationList[index];
        list.add(
          InkWell(
            onTap: () {
              onChange(_data);
              Navigator.of(context).pop();
            },
            child: Container(
              margin: EdgeInsets.only(bottom: 10),
              decoration: BoxDecoration(color: Global.backgroundColor),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Avatar(
                    sex: 1,
                    index: _data['code'],
                    size: MediaQuery.of(context).size.width / 5,
                    shadow: false,
                  ),
                  SizedBox(height: 5),
                  Text(
                    _data['name'],
                    style: TextStyle(
                      fontSize: 14,
                      fontWeight: FontWeight.w400,
                      color: Color(0xFF478FC2),
                    ),
                  ),
                  SizedBox(height: 5),
                  Text(
                    _data['date'],
                    style: TextStyle(
                      fontSize: 12,
                      fontWeight: FontWeight.w400,
                      color: Color(0xFF478FC2).withOpacity(0.7),
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      });
      return list;
    }

    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text(
            '选择星座',
            style: TextStyle(
              color: Global.fontColor,
              fontSize: 16,
            ),
          ),
          content: SingleChildScrollView(
            child: Container(
              decoration: BoxDecoration(color: Global.backgroundColor),
              child: Wrap(
                alignment: WrapAlignment.spaceBetween,
                children: modalChildren(),
              ),
            ),
          ),
        );
      },
    );
  }
}
